package factory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class MyFactory {
    private Properties properties=new Properties();
    public MyFactory(){
    }
    public MyFactory(String config)throws IOException{
        //通过反射类获取配置文件信息
        InputStream resourceAsStream=MyFactory.class.getResourceAsStream(config);
        //读取配置文件
        properties.load(resourceAsStream);
    }

        public Object getBean(String name) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        //1。通过name，获取对应路径
            String classPath=properties.getProperty(name);
            Class <?> aClass=Class.forName(classPath);
            //通过反射对象调用构造器方法实例化对象
            return aClass.newInstance();
        }

}
